<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>登录日志</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta http-equiv="pragma" content="no-cache"/>
	<meta http-equiv="cache-control" content="no-cache"/>
	<meta http-equiv="expires" content="0"/>
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3"/>
	<meta http-equiv="description" content="This is my page"/>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/bootstrap/css/bootstrap.min.css"/>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/easyUI/easyui.css">
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/publicStyle.css"/><!--分页样式-->
	<!-- Sweet Alert -->
	<link rel="stylesheet" type="text/css"
		  href="${pageContext.request.contextPath}/css/plugins/sweetalert/sweetalert.css">
</head>
<body style="overflow: hidden; width: 98%; height: 100%;padding-left: 5px;">
<!-- 工具按钮区 -->
<form class="form-horizontal" action="" >
	<table class="table-condensed">
		<tbody>
		<tr>
			<td style="padding-left: 0;">
				<a id="deleteUser" class="btn btn-danger operas" onclick="delMoreLog()"><span class="glyphicon glyphicon-remove"></span>&nbsp;批量删除</a>
			</td>
		</tr>
		</tbody>
	</table>
</form>
<div class="panel panel-primary" style="padding-left: px;">
	<div class="panel-heading" style="background-color: #11a9e2;">
		<label>登录日志</label>
	</div>
	<div class="panel-body">
		<table class="table table-bordered table-hover" style="margin-bottom: 0;">
			<thead>
			<tr style="font-size: 12px;" align="center">
				<th style="text-align: center;"><input id="checkAll" type="checkbox"/></th>
				<th style="text-align: center;">用户名</th>
				<th style="text-align: center;">登录时间</th>
				<th style="text-align: center;">外网IP remoteIP</th>
				<th style="text-align: center;">内网ip clientIP</th>
				<th style="text-align: center;">登录状态</th>
			</tr>
			</thead>
			<tbody id="data_info">

			</tbody>
		</table>

	</div>
	<!--分页条-->
	<div class="pager" id="pager"></div>
</div>

<div id="divDialog">
	<!-- 放置一个添加用户的界面  -->
	<iframe id="iframe" frameborder="0" style="width: 100%;height: 100%;"></iframe>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/jquery/jquery.min.js"></script>
<script type="text/javascript"
		src="${pageContext.request.contextPath}/resources/jquery/jquery-migrate-1.2.1.min.js"></script>
<!--分页  -->
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.myPagination.js"></script>
<!-- 导入bootStrap的库 -->
<script type="text/javascript"
		src="${pageContext.request.contextPath}/resources/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/easyUI/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/easyUI/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/plugins/layer/2.4/layer.js"></script>
<script type="text/javascript"
		src="${pageContext.request.contextPath}/resources/plugins/layer/2.4/LayConstant.js"></script>
<!--弹窗-->
<script type="text/javascript"
		src="${pageContext.request.contextPath}/resources/plugins/sweetalert/sweetalert.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
       sellog(1);
    });

    var pageSize =7;
    function sellog(pageNo){
        var params={"pageNo":pageNo,"pageSize":pageSize};
        var obj = $("#data_info");
        obj.empty();
        $.ajax({
            url:'${pageContext.request.contextPath}/loginlog/selectLoginLog.jspx',
            data:params,
            type:'post',
            dataType:'json',
            success:function(data){
                if(data.code==0){
                    var content = data.content[0].info,code="";
                    var pageCount = data.content[0].pagetotal;//总页数
                    if (content.length < 1) {
                        layer.msg("暂无数据", {icon: 5, time: LayUIConstant.TIP_TIME});
                    } else {
                        for (var i = 0; i < content.length; i++) {
                            var logId = content[i].sysid;
                            code +=  '<tr id="dataTr_'+i+'" align="center">'+
                                '<td>'+
                                '<input id="box_'+i+'" name="box" align="center" type="checkbox" value="'+logId+'" >'+
                                '</td>'+
                                '<td>'+content[i].username+'</td>'+
                                '<td>'+content[i].loginTime+'</td>'+
                                '<td>'+content[i].remoteIP+'</td>'+
                                '<td>'+content[i].clientIP+'</td>'+
                                '<td>'+content[i].status+'</td>'+
                                '<td>'+
                                '<button type="button" class="btn btn-danger" onclick="del(\'' + logId + '\')">删除</button>'+
                                '</td>'+
                                '</tr>';
                        }
                        obj.append(code);
                        if (pageCount > 0) {
                            //分页
                            $("#pager").myPagination({
                                currPage: pageNo, //初始选择的页数
                                pageCount: pageCount,//总页数
                                pageSize: pageSize //显示多少页
                            });
                        }

                        //全选
                        //获取所有的name=box的对象
                        var dataBoxs = $("input[name='box'][id^='box_']");
                        $("#checkAll").click(function(){
                            dataBoxs.attr("checked",this.checked);
                        });
                        //如果没有全部选中，全选按钮不选中
                        var boxSize = dataBoxs.length;
                        dataBoxs.on("click",function(event){
                            event.stopPropagation();
                            var checkedBoxs = dataBoxs.filter(":checked");
                            $("#checkAll").attr("checked",checkedBoxs.length == boxSize);
                        });

                    }


                }else{
                    layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
                }
            },
            error:function(data){
                layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
            }
        });
    }
    function pageOnClick(page) {
        sellog(page);
    }
    //分页文本框中直接输入时触发： properchange：适用IE9以及以上版本  onchange：IE不适用  两者必须有获取焦点失去焦点后才能触发
    function inputChange() {
        var pageNo = $('#pageInput').val();//文本框中当前页
        sellog(pageNo);
    }




    //删除日志
    function del(logId){
        if(!confirm("是否删除选中的项？")){
            return;
        }
        $.ajax({
            url:'${pageContext.request.contextPath}/loginlog/delLoginlog.jspx',
            data:{"logId":logId},
            type:'post',
            dataType:'json',
            success:function(data){
                if(data.code == 0){
                    layer.msg(data.message, {icon: 1, time: LayUIConstant.TIP_TIME});
                    setTimeout(function () {
                        //location.href = "${pageContext.request.contextPath}/loginlog/selectLoginLog.jspx";
						window.location.reload();
                    }, 1500);
                }else{
                    layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
                }
            },
            error:function (data) {
                layer.msg(data.message, {icon: 5, time: LayUIConstant.TIP_TIME});
            }
        });
    }




    //批量删除
    function delMoreLog(){
        var dataBoxss = $("input[name='box'][id^='box_']");
        var checkedId = dataBoxss.filter(":checked");
        var idArr = [];
        if(checkedId.length < 1){
            swal("请选择需要删除的项!","","error");
        }else{
            for(var i = 0;i < checkedId.length;i++){
                idArr.push(checkedId.eq(i).val());
            }
            if(!confirm("是否删除选中的项？")){
                return;
			}
            $.ajax({
                url:"${pageContext.request.contextPath}/loginlog/delMoreLog.jspx",
                data:{"ids":idArr.join(",")},
                type:"post",
                dataType:"json",
                success:function (data) {
                    if(data.code == 0){
                        swal("删除成功!","","success");
                        setTimeout("myrefresh()",1500);
                    }else{
                        swal("删除失败!","","error");
                    }
                },
                error:function (data) {
                    swal("报错了。。","","error");
                }
            });
        }
    }
    function myrefresh(){
        window.location.reload();
    }
</script>


</body>

</html>





































